//
//  RootViewController.m
//  ZOL在线
//
//  Created by MS on 15/9/1.
//  Copyright (c) 2015年 赵向禹. All rights reserved.
//

#import "RootViewController.h"
#import "PictureViewController.h"
#import "JokeingViewController.h"
#import "RDVTabBarItem.h"
#import "MusicViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setViewControllers];
}

-(void)setViewControllers
{
       PictureViewController * PictureVC = [[PictureViewController alloc] init];
    UINavigationController * PictureNav = [[UINavigationController alloc]initWithRootViewController:PictureVC];
   
    
    JokeingViewController* JokeVC = [[JokeingViewController alloc] init];
    UINavigationController *JokeNav = [[UINavigationController alloc] initWithRootViewController:JokeVC];
    
    MusicViewController * musicVC = [[MusicViewController alloc]init];
    UINavigationController * musicNav = [[UINavigationController alloc]initWithRootViewController:musicVC];
    

    JokeVC.navigationItem.title = @"段子";
    PictureVC.navigationItem.title = @"视频";
    musicVC.navigationItem.title = @"声音";
    
    [self setViewControllers:@[PictureNav,JokeNav,musicNav]];
    
    [self customizeTabBarForController:self];
    
}

- (void)customizeTabBarForController:(RDVTabBarController *)tabBarController {

    UIImage *finishedImage = [UIImage imageNamed:@"tabbar_selected_background"];
    UIImage *unfinishedImage = [UIImage imageNamed:@"tabbar_normal_background"];
    NSArray * tabBarItemImages =@[@"", @"",@""];
    NSArray *titles = @[@"视频",@"段子",@"声音"];
    NSInteger index = 0;
    NSDictionary * textAttributes_normal=nil;
    NSDictionary * textAttributes_selected =nil;
    
    //设置，字体颜色和图片颜色一致
    if (NSFoundationVersionNumber>NSFoundationVersionNumber_iOS_6_1) {
        textAttributes_normal=@{NSFontAttributeName:[UIFont systemFontOfSize:12],
                                NSForegroundColorAttributeName:[UIColor colorWithRed:65/255.0 green:65/255.0 blue:65/255.0 alpha:1.0],
                                };
        textAttributes_selected=@{NSFontAttributeName:[UIFont systemFontOfSize:12],
                                  NSForegroundColorAttributeName:[UIColor colorWithRed:14/255.0 green:154/255.0 blue:255/255.0 alpha:1.0],
                                  };
    }
    for (RDVTabBarItem * item in [[tabBarController tabBar] items]) {
        item.unselectedTitleAttributes=textAttributes_normal;
        item.selectedTitleAttributes=textAttributes_selected;
        
        [item setBackgroundSelectedImage:finishedImage withUnselectedImage:unfinishedImage];
        UIImage *selectImage=[UIImage imageNamed:[NSString stringWithFormat:@"%@_press",[tabBarItemImages objectAtIndex:index]]];
        UIImage * unselectImage =[ UIImage imageNamed:[NSString stringWithFormat:@"%@",[tabBarItemImages objectAtIndex:index]]];
        [item setFinishedSelectedImage:selectImage withFinishedUnselectedImage:unselectImage];
        item.title=titles[index];
        index++;
    }

    
    

}
@end
